/*
 * @Author: soso
 * @Date: 2022-02-08 17:18:19
 * @LastEditTime: 2022-02-17 15:39:54
 * @LastEditors: Please set LastEditors
 * @Description: 全部监视命令的磁盘处理
 * @FilePath: /sync-client/notify/ntfs.go
 */

package notify

import (
	"gomeshcli/sconfig"
	"io/ioutil"
	"os"

	"gitee.com/kimsoso/go-utils/utils"
	"github.com/vmihailenco/msgpack"
)

// 往磁盘文件添加命令
func (ntfs *Ntfs) appendFullFile(ntf sconfig.Snotify) {
	_ntfs := []*sconfig.Snotify{}
	_ntfs = append(_ntfs, &ntf)

	data, _ := msgpack.Marshal(_ntfs)
	utils.AppendFile(pathOfFull, data)
}

// 加载监测命令列表
func (ntfs *Ntfs) loadFullNtfs() {
	ntfs.fullNtfs = []*sconfig.Snotify{}
	buf, err := ioutil.ReadFile(pathOfFull)

	if err == nil && len(buf) > 0 {
		msgpack.Unmarshal(buf, &(ntfs.fullNtfs))
	}
}

// 清空监测命令列表
func (ntfs *Ntfs) clearFullNtfs() {
	ntfs.fullNtfs = []*sconfig.Snotify{}
	os.Truncate(pathOfFull, 0)
}
